<template>
  <section class="filter">
    <div class="filter-container">
      <el-form ref="form" :inline="true">
        <el-form-item label="频道名称：">
          <el-input
            v-model="name"
            placeholder="请输入频道名称"
            class="filter-item"
            clearable
            @change="queryData"
          />
        </el-form-item>
        <el-form-item label="账号状态：">
          <!-- TODO: clearable按钮还原，下拉列表宽度，输入框宽度 -->
          <el-select v-model="selectState" placeholder="请选择状态" clearable @change="changeState">
            <el-option
              v-for="item in stateList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>

    <el-button type="success" icon="el-icon-circle-plus-outline" @click="addData">新建</el-button>
    <el-button type="success" icon="el-icon-circle-plus-outline" @click="exportExcel">导出</el-button>
    <el-button type="success" icon="el-icon-circle-plus-outline" @click="importExcel">导入</el-button>

    <el-button type="success" icon="el-icon-circle-plus-outline" @click="download">下载</el-button>


    <el-dialog title="导入" :visible.sync="dialogImportVisible" width="480px">
      <el-form label-position="right" label-width="170px">
        <el-form-item label="文件">

          <el-upload
            :multiple="false"
            :on-success="onUploadSuccess"
            :action="'http://localhost:9001/api/v1/channel/upload'"

            class="upload-demo">
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传xls文件，且不超过500kb</div>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogImportVisible = false">取消</el-button>
      </div>
    </el-dialog>


  </section>
</template>

<script>

  import channel from '@/api/channel.js'

  export default {
    props: ['changeParam', 'addData'],
    data() {
      return {
        stateList: [
          {label: '全部', value: ''},
          {label: '启动', value: 1},
          {label: '禁用', value: 0}
        ],
        name: '',
        selectState: '',
        dialogImportVisible: false
      }
    },
    methods: {
      download() {
        // window.location.href = 'E:\\java\\project-usian-leadnews-admin-vue-teacher\\src\\views\\channel\\template'.
        window.location.href = '../../../../static/频道.xlsx'
      },
      onUploadSuccess(response, file) {
        this.$message.info('上传成功')
        this.dialogImportVisible = false
        // this.getDictList(1)
      },
      importExcel() {
        // window.location.href = '../../../../static/频道.xlsx';
        this.dialogImportVisible = true
      },
      exportExcel() {
        window.location.href = 'http://localhost:9001/api/v1/channel/download'
      },
      queryData() {
        const params = {
          name: ''
        }

        if (this.name) {
          params.name = this.name
        }
        // TODO: 新接口的字段需要问后端老师
        // if (this.selectState !== '') {
        //   params.push({
        //     filed: 'status',
        //     type: 'eq',
        //     value: this.selectState
        //   })
        // }
        this.changeParam(params)
      },
      // 切换状态
      changeState() {
        this.queryData() // 查询数据
      }
    }
  }
</script>
